/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package objective_functions;

/**
 *
 * @author robson
 */
public class ZDT4_F2 implements ObjectiveFunction {
    
    private double gValue;

    public double function( double[] dimension ) {
        
        return g( dimension ) * ( 1.0 - Math.sqrt( dimension[0]/g( dimension ) ) );
    }
    
    private double g ( double[] dimension ) {
        double sum = 0.0;
//        double result;
        
        for( int i = 1; i < dimension.length; i++ ) {
            sum += Math.pow( dimension[i], 2 ) - ( 10.0 * Math.cos( 4.0 * Math.PI * dimension[i] ) );
        }
        
        gValue = 1.0 + ( 10.0 * (dimension.length - 1) ) + sum;
        
        return gValue;
        
//        return 1 + ( ( 9 * sum ) / ( dimension.length - 1 ) ); 
    }

    public double getGValue() {
        return gValue;
    }
}
